﻿using System;
using System.ComponentModel;
using System.Net;
using System.Xml.Linq;

namespace BackupRestoreSoftwares
{
    public class CheckUpdate
    {
        public string GetNewVersion { get; set; }
        public string GetLinkMain { get; set; }
        public string GetListFile { get; set; }
        public string GetName { get; set; }

        public bool CheckUpdate1(string url)
        {
            try
            {
                XElement sitemap = XElement.Load(url);
                if (sitemap.HasElements)
                {
                    GetNewVersion = sitemap.Element("version").Value;
                    GetLinkMain = sitemap.Element("link").Value;
                    GetListFile = sitemap.Element("rar").Value;
                    return true;
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public void Downloadrar(string lnk_dl, string path_dl)
        {
            var webClient = new WebClient();
            webClient.DownloadFileCompleted += Completed;
            webClient.DownloadProgressChanged += ProgressChanged;
            webClient.DownloadFileAsync(new Uri(lnk_dl), path_dl);
        }

        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            // progressBar.Value = e.ProgressPercentage;
        }

        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            // MessageBox.Show("Download completed!");
        }
    }
}